<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />
	</head>

	<body>
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field">
				<legend>添加分类</legend>
			
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
					<div class="layui-tab-content" >
						<!-- 基础设置 开始-->
						<form class="layui-form" action="" id="form">
							<div class="layui-form-item">
							    <label class="layui-form-label">分类标题</label>
							    <div class="layui-input-inline">
							      <input type="text" name="name" value="{$info['name']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">分类图标</label>
								<div class="layui-upload">
									<input type="file" name="thumb" class="layui-upload-file" id="thumb">
									<input type="hidden" name="thumbs" id="thumbs" value="{$info['thumbs']}">
									<div class="layui-upload-list" style="margin-top: 10px; margin-left: 110px;">
									    <img src="{$info['thumbs']}" class="layui-upload-img" id="show"  style="width:100px">
									    <p id="demoText"></p>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
							      <label class="layui-form-label">所属分类</label>
							      <div class="layui-input-inline">
							        <select name="pid">
							        	<option value="0">顶级分类</option>
								        <optgroup label="请选择分类">
								        	{loop $list $item}
								            <option value="{$item['id']}" {if $info['pid']==$item['id']}selected="selected"{/if}>{$item['name']}</option>
								            {/loop}
								        </optgroup>
							        </select>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">描述第一行</label>
							    <div class="layui-input-inline">
							      <input type="text" name="desc1" value="{$info['desc1']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							      <span style="color:red">生成个人分享图第一句描述</span>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">描述第二行</label>
							    <div class="layui-input-inline">
							      <input type="text" name="desc2" value="{$info['desc2']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							      <span style="color:red">生成个人分享图第二句描述</span>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">排序</label>
							    <div class="layui-input-inline">
							      <input type="num" name="sort" value="{$info['sort']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<input type="hidden" name="id" value="{$info['id']}" >
							<div class="layui-form-item">
							    <div class="layui-input-block" >
							      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="sub">立即提交</button>
							      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
							    </div>
							</div>

							</form>
						<!-- 题目设置 结束-->
					</div>
				</div>	
			</fieldset>
		</div>

		<script type="text/javascript" src="/addons/hc_answer/template/plugins/layui/layui.js"></script>
		<script>
			layui.use(['form','upload','layer'], function() {
				var $ = layui.jquery,
				upload = layui.upload,
				form = layui.form();
				form.render();
				 //普通图片上传
				layui.upload({
					elem: '#thumb',
					url: '{php echo $this->createWebUrl("Uploadimg");php}',
					success: function(res){
						if(res.code==1){
							$('#show').attr('src', res.path);
							$('#thumbs').val(res.path);
						}
					}
				});  



				form.on('submit(sub)', function(data) {
					$.ajax({
			            url:"{php echo $this->createWebUrl('categorydo');php}",
			            data:$('#form').serialize(),
			            type:"post",
			            dataType:"json",
			            success:function(data){
			            	if(data.code=='1'){
			                	layer.alert(data.msg, {icon: 6},function(index){
			                		var index = parent.layer.getFrameIndex(window.name);
			                		parent.layer.close(index)
			                	});
								
			            	}else{
			                	layer.alert(data.msg, {icon: 5});
			            	}
			            },
			            error:function(data){
			                layer.alert('请稍后重试', {icon: 5});
			            }
			        });
					return false;
				});
				
			});
		</script>

	</body>

</html>